import { createI18n } from 'vue-i18n'

const savedLocale = (typeof window !== 'undefined' && localStorage.getItem('app_locale')) || 'zh-CN'

export const messages = {
  'zh-CN': {
    app: {
      switchLang: '切换语言',
    },
    login: {
      title: '在线旅游后台管理',
      subtitle: '欢迎使用旅游管理系统 · 请登录',
      emailPlaceholder: '你的邮箱',
      passwordPlaceholder: '你的密码',
      urlPlaceholder: '输入图片地址，支持 http(s) 或本地相对路径',
      signIn: '登录',
      bgSetting: '设置背景',
      dialogTitle: '自定义背景',
      tabUrl: '图片地址',
      tabUpload: '本地上传',
      tabPreview: '预览',
      previewTip: '输入地址或上传后可预览',
      fit: '适应方式',
      fitCover: '自适应裁剪（推荐）',
      fitContain: '完整显示',
      fitFill: '拉伸填充',
      resetDefault: '恢复默认',
      apply: '应用',
      selected: '已选择：{name}',
      notReadFile: '未读取到文件，请重试',
      pleaseInput: '请先输入图片地址或上传图片',
      updated: '背景已更新',
      restored: '已恢复默认背景',
      loginSuccess: '登录成功',
      emailRequired: '请输入邮箱',
      emailInvalid: '邮箱格式不正确',
      passwordRequired: '请输入密码',
      passwordMin: '至少 6 位字符',
    },
  },
  en: {
    app: {
      switchLang: 'Switch language',
    },
    login: {
      title: 'Travel Admin',
      subtitle: 'Welcome to the travel management system · Please sign in',
      emailPlaceholder: 'Your email',
      passwordPlaceholder: 'Your password',
      urlPlaceholder: 'Enter image URL, supports http(s) or local relative path',
      signIn: 'Sign In',
      bgSetting: 'Background',
      dialogTitle: 'Background Settings',
      tabUrl: 'Image URL',
      tabUpload: 'Upload',
      tabPreview: 'Preview',
      previewTip: 'Enter a URL or upload to preview',
      fit: 'Fit Mode',
      fitCover: 'Cover (recommended)',
      fitContain: 'Contain',
      fitFill: 'Fill',
      resetDefault: 'Reset',
      apply: 'Apply',
      selected: 'Selected: {name}',
      notReadFile: 'No file read, please retry',
      pleaseInput: 'Enter an image URL or upload first',
      updated: 'Background updated',
      restored: 'Restored to default',
      loginSuccess: 'Signed in successfully',
      emailRequired: 'Email is required',
      emailInvalid: 'Invalid email format',
      passwordRequired: 'Password is required',
      passwordMin: 'At least 6 characters',
    },
  },
}

const i18n = createI18n({
  legacy: false,
  globalInjection: true,
  locale: savedLocale,
  fallbackLocale: 'zh-CN',
  messages,
})

export default i18n
